﻿    $(document).ready(function () {
        var oTable = $('#datalist').dataTable({
            "bSort": false,
            "sPaginationType": "full_numbers",
            "bProcessing": true,
            "bServerSide": true,
            
            "sAjaxSource": "registration/tablelist",
            "aoColumns": [
                            { "mDataProp": "Id" },
                            { "mDataProp": "MedicalRecordNumber" },
                            { "mDataProp": "PatientName" },
                            { "mDataProp": "Birthdate" },
                            { "mDataProp": "PhoneNumber" },
                            { "mDataProp": "AddressDesc" }
                            //{"mDataProp": "Addresses.0.State" }

                        ],
            "aoColumnDefs": [
                                {
                                    "fnRender": function (o) {
                                        return "<center><a class='tooltip' title='select this record' href='registration/register/?PatientId=" + o.aData['Id'] + "'><img src='/images/Icons/table.png'/></a> </center>";
                                    },
                                    "aTargets": [0]
                                }                           
                        ],
            "fnServerData": function (sSource, aoData, fnCallback) {
                aoData.push({ "name": "mrn", "value": $('#TextboxMrn').val() });
                aoData.push({ "name": "patientname", "value": $('#TextboxPatientname').val() });
                aoData.push({ "name": "dob", "value": $('#TextboxDob').val() });
                jQuery.ajax({
                    "dataType": 'json',
                    "type": "GET",
                    "url": "registration/tablelist",
                    "data": aoData,
                    "success": fnCallback
                });
            }
        });

        function checkForEnter(event) {
            if (event.keyCode == 13) {
                oTable.fnDraw();
            }
        }

        $('#TextboxMrn').keypress(checkForEnter);
        $('#TextboxPatientname').keypress(checkForEnter);
        $('#TextboxDob').keypress(checkForEnter);
        $('#buttonSearch').click(function () { oTable.fnDraw(); });
    });
